package com.oyjd.beauty.fw.sql.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.oyjd.beauty.fw.sql.dao.SqlDao;
import com.oyjd.beauty.fw.sql.service.SqlService;

/**
 * sql Service接口实现
 * 
 * @author 欧建东
 * @version 1.0
 */
@Component
@Transactional
public class SqlServiceImpl implements SqlService {

	private SqlDao dao;

	@Autowired
	public void setDao(SqlDao dao) {
		this.dao = dao;
	}

	/**
	 * 查询数据
	 * 
	 * @param sql
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	@Transactional(readOnly = true)
	public List query(String sql) {
		return dao.getSession().createSQLQuery(sql).list();
	}

	/**
	 * 执行sql
	 * 
	 * @param sql
	 * @return
	 */
	public int execute(String sql) {
		return dao.getSession().createSQLQuery(sql).executeUpdate();
	}

}
